<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
</head>
<body>
<div class="layui-fluid">
    <table class="layui-hide" id="WaitFinishTask" lay-filter="WaitFinishTask"></table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs" lay-event="update">编辑</a>
    </script>
</div>
<script th:src="@{/layui/layui.js}"></script>
<script type="text/javascript" th:inline="javascript">
    layui.use(['table','jquery'], function () {
        var table = layui.table;
        var $ = layui.jquery ;
        var username = /*[[${session.user.name}]]*/ "用户名称";
        let tableIns = table.render({
            elem: '#WaitFinishTask'
            , url: '/task/WaitFinishTask/' + username
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , skin: 'nob'
            , cols:
                [
                    [
                        {field: 'name', width: '10%', title: '任务人', sort: true, align: 'center'}
                        , {field: 'id', width: '20%', title: '零件编号', sort: true, align: 'center'}
                        , {field: 'monovalent', width: '10%', title: '零件单价', align: 'center'}
                        , {field: 'status', width: '10%', title: '任务状态', align: 'center'}
                        , {
                        field: 'createTime', title: '任务创建时间', width: '17%', align: 'center',
                        templet: "<div>{{d.createTime == null ? '' : layui.util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss')}}</div>",
                    }
                        , {
                        field: 'finishTime', width: '18%', title: '任务结束时间', sort: true, align: 'center',
                        templet: "<div>{{d.finishTime == null ? '' : layui.util.toDateString(d.finishTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"
                    },
                        {
                            fixed: 'right',
                            title: '操作',
                            width: "15%",
                            align: 'center',
                            toolbar: '#barDemo'
                        }
                    ]
                ]
        });

        table.on('tool(WaitFinishTask)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data, //获得当前行数据
                layEvent = obj.event; //获得 lay-event 对应的值
            let id = data.id;
            if (layEvent === 'update') {
                layer.msg('更新');
                layer.confirm('确认已完成',{icon:1},function(){
                    $.post("/task/updateWaitFinishTask",{id},function(res){
                        if(res.code == 0){
                            layer.msg(res.msg);
                        }else{
                            layer.msg(res.msg);
                        }
                    })
                })
            }
        });
    });
</script>
</body>
</html>